package com.powernode.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.powernode.domain.Activity;
import com.powernode.mapper.ActivityMapper;
import com.powernode.model.BaseQuery;
import com.powernode.query.ActivityQueryCondition;
import com.powernode.service.ActivityService;
import com.powernode.util.AuthUtils;
import com.powernode.vo.ActivityDetailInfoVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class ActivityServiceImpl implements ActivityService {

    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public PageInfo<ActivityDetailInfoVo> queryActivityListByPage(ActivityQueryCondition activityQueryCondition) {
        // 设置分页参数
        PageHelper.startPage(activityQueryCondition.getCurrent(),activityQueryCondition.getSize());
        // 查询数据
        List<ActivityDetailInfoVo> activityDetailInfoVoList = activityMapper.selectList(new BaseQuery(),activityQueryCondition);
        // 封装分页对象
        return new PageInfo<>(activityDetailInfoVoList);
    }

    @Override
    public Boolean saveActivity(Activity activity) {
        activity.setOwnerId(AuthUtils.getLoginUserId());
        activity.setCreateTime(new Date());
        activity.setCreateBy(AuthUtils.getLoginUserId());
        return activityMapper.insert(activity)>0;
    }

    @Override
    public Activity queryActivityById(Integer activityId) {
        return activityMapper.selectByPrimaryKey(Long.valueOf(activityId));
    }

    @Override
    public Boolean modifyActivity(Activity activity) {
        activity.setEditTime(new Date());
        activity.setEditBy(AuthUtils.getLoginUserId());
        return activityMapper.updateByPrimaryKeySelective(activity)>0;
    }

    @Override
    public ActivityDetailInfoVo queryActivityDetailInfoById(Integer activityId) {
        return activityMapper.selectActivityDetailInfoById(activityId);
    }

    @Override
    public List<Activity> queryAllActivityList() {
        return activityMapper.selectAllList();
    }
}
